package com.laysonx.easy.invoke.core;

import com.laysonx.easy.invoke.support.InvokeMonitor;
import com.laysonx.easy.invoke.support.Param;
import com.laysonx.easy.invoke.support.Resource;
import com.laysonx.easy.invoke.support.ResourcePool;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 装配数据清理、数据验证处理器
 *
 * @author: Laysonx
 * @date: 2019/9/27 15:51
 */
public class InvokeMonitorProcessor implements BeanPostProcessor, ApplicationContextAware {

    private static ApplicationContext context = null;

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        InvokeMonitor invokeMonitor = context.getBean(InvokeMonitor.class);
        if(bean instanceof EasyInvokePostProcessor){
            invokeMonitor.addPostProcessor((EasyInvokePostProcessor) bean);
        }
        return bean;
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
